package jdly.water.api.controller.data;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import jdly.water.api.common.service.R;
import jdly.water.api.model.PageModel;
import jdly.water.api.service.data.DataService;
import jdly.water.api.util.DateUtils;
import jodd.util.StringUtil;

@RestController
public class DataController {

	@Autowired
	private DataService dataService;

	@GetMapping("/metermonitor")
	public R metermonitor(String meternumber, String begin, String end, String orgname,String building,String unit,String room,PageModel page) {
		LinkedHashMap param = new LinkedHashMap();
		param.put("meter.meterNumber", meternumber);
		param.put("meter.building.org.orgname", orgname);
		param.put("meter.building.floor", building);
		param.put("meter.building.unit", unit);
		param.put("meter.building.room", room);
		Map<String, Object> beginmap = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(begin)) {
			beginmap.put("readtime", DateUtils.strToDate(begin,"yyyy-MM-dd'T'HH:mm:ss'.'sss'Z'"));
		}
		Map<String, Object> endmap = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(end)) {
			endmap.put("readtime", DateUtils.strToDate(end,"yyyy-MM-dd'T'HH:mm:ss'.'sss'Z'"));
		}
		return dataService.metermonitor(param, null, page, beginmap, endmap);
	}

	@GetMapping("/bmmonitor")
	public R bmmonitor(String orgname,String meternumber, String begin, String end, PageModel page) {
		LinkedHashMap param = new LinkedHashMap();
		param.put("meter.meterNumber", meternumber);
		param.put("meter.org.orgname", orgname);
		param.put("meter.meterModel", "栋表");
		Map<String, Object> beginmap = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(begin)) {
			beginmap.put("readtime", DateUtils.strToDate(begin));
		}
		Map<String, Object> endmap = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(end)) {
			endmap.put("readtime", DateUtils.strToDate(end));
		}
		return dataService.bmetermonitor(param, null, page, beginmap, endmap);
	}

	
	@GetMapping("/tmmonitor")
	public R tmmonitor(String orgname,String meternumber, String begin, String end, PageModel page) {
		LinkedHashMap param = new LinkedHashMap();
		param.put("meter.meterNumber", meternumber);
		param.put("meter.org.orgname", orgname);
		param.put("meter.meterModel", "总表");
		Map<String, Object> beginmap = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(begin)) {
			beginmap.put("readtime", DateUtils.strToDate(begin));
		}
		Map<String, Object> endmap = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(end)) {
			endmap.put("readtime", DateUtils.strToDate(end));
		}
		return dataService.bmetermonitor(param, null, page, beginmap, endmap);
	}

}
